﻿using System;
using System.Data;
using System.Data.Common;

namespace Songhay.Data.GenericWeb.Procedures
{
    using Songhay.Data.GenericWeb.Properties;

    /// <summary>
    /// Insert procedures into the DBMS.
    /// </summary>
    public static partial class Insert
    {
        /// <summary>
        /// Inserts SegmentDocument data into the DBMS.
        /// </summary>
        /// <param name="commonConnection">The Common connection.</param>
        /// <param name="segmentID">The Segment ID.</param>
        /// <param name="documentID">The Document ID.</param>
        public static void SegmentDocument(DbConnection commonConnection, object segmentID, object documentID)
        {
            if(commonConnection == null) throw new ArgumentNullException("connection", "The connection is null.");

            using(DbCommand cmd = commonConnection.CreateCommand())
            {
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = Resources.InsertSegmentDocument;

                DbParameter parameter;

                parameter = cmd.CreateParameter();
                parameter.ParameterName = "@SegmentId";
                parameter.Value = segmentID;
                cmd.Parameters.Add(parameter);

                parameter = cmd.CreateParameter();
                parameter.ParameterName = "@DocumentId";
                parameter.Value = documentID;
                cmd.Parameters.Add(parameter);

                cmd.ExecuteNonQuery();
            }
        }
    }
}
